package org.toolbook.config;



import org.toolbook.controller.CodeController;
import org.toolbook.controller.DiaryController;
import org.toolbook.controller.FootController;
import org.toolbook.controller.GeneralController;
import org.toolbook.controller.IndexController;
import org.toolbook.controller.NewWordController;
import org.toolbook.controller.UserController;
import org.toolbook.controller.UtilsController;
import org.toolbook.model.Account;
import org.toolbook.model.Admin;
import org.toolbook.model.Code;
import org.toolbook.model.Diary;
import org.toolbook.model.Foot;
import org.toolbook.model.General;
import org.toolbook.model.NewWord;
import org.toolbook.model.Photo;
import org.toolbook.model.Store;
import org.toolbook.model.User;
import org.toolbook.util.PropUtil;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.spring.SpringPlugin;
import com.jfinal.render.ViewType;


/**
 * toolbook的jfinal主配置类
 * @author meigang 
 * @date 2015-06-19 21:00
 *
 */
public class ToolBookConfig extends JFinalConfig{

	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setDevMode(Boolean.parseBoolean(PropUtil.getProperty("devMode")));
		me.setViewType(ViewType.JSP);
	}
	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/", IndexController.class);
		me.add("/utils", UtilsController.class);
		me.add("/user", UserController.class);
		me.add("/code",CodeController.class);
		me.add("/newword",NewWordController.class);
		me.add("/diary",DiaryController.class);
		me.add("/general",GeneralController.class);
		me.add("/foot",FootController.class);
	}
	/**
	 * 插件配置
	 */
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		//加入spring插件
		SpringPlugin springPlugin = new SpringPlugin();
		me.add(springPlugin);
		
		//加载数据库插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropUtil.getProperty("jdbcUrl"),PropUtil.getProperty("user"),PropUtil.getProperty("password"),PropUtil.getProperty("driverClass"));
		c3p0Plugin.setMaxIdleTime(3000);
		me.add(c3p0Plugin);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);

		// 添加映射关系
		String table_pre = PropUtil.getProperty("tablePre");
		arp.addMapping(table_pre + "user", User.class);
		arp.addMapping(table_pre + "admin", Admin.class);
		arp.addMapping(table_pre + "general", General.class);
		arp.addMapping(table_pre + "code", Code.class);
		arp.addMapping(table_pre + "account", Account.class);
		arp.addMapping(table_pre + "diary", Diary.class);
		arp.addMapping(table_pre + "new_word", NewWord.class);
		arp.addMapping(table_pre + "foot", Foot.class);
		arp.addMapping(table_pre + "photo", Photo.class);
		arp.addMapping(table_pre + "store", Store.class);
	}
	/**
	 * 拦截器配置
	 */
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

	

}
